package com.beeway.blackgoose.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.beeway.blackgoose.BaseApp;
import com.beeway.blackgoose.R;
import com.beeway.blackgoose.adapter.CouponListAdaper;
import com.beeway.blackgoose.bean.ListMessage;
import com.beeway.blackgoose.constants.Config;
import com.beeway.blackgoose.utils.Utils;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CouponAllFragment extends Fragment implements PullToRefreshBase.OnRefreshListener2<ListView> {

    private String type;
    private View couponView;
    private List<ListMessage> couponDates;
    private CouponListAdaper couponListAdaper;

    @ViewInject(R.id.coupon_show_ptrlv)
    private PullToRefreshListView couponPtrlv;

    public CouponAllFragment() {

    }

    public static CouponAllFragment getInstance(String type) {
        CouponAllFragment all = new CouponAllFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Config.COUPON_TYPE, type);
        all.setArguments(bundle);
        return all;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            type = getArguments().getString(Config.COUPON_TYPE);//注意这里默认需要api10是不行的
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        couponView = inflater.inflate(R.layout.fragment_coupon_all, container, false);
        ViewUtils.inject(this, couponView);
        initView();
        initDate();
        return couponView;
    }

    //根据类型来加载不同数据
    private void initView() {
        if (type.equals(Config.COUPON_ALL)) {

        } else if (type.equals(Config.COUPON_UNUSED)) {

        } else if (type.equals(Config.COUPON_USED)) {

        } else if (type.equals(Config.COUPON_OVERDUE)) {

        }
    }

    private void initDate() {
        couponPtrlv.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        couponDates = new ArrayList<>();
        getData();
        couponListAdaper = new CouponListAdaper(BaseApp.getContext(), couponDates, Utils.getBitmapUtils(BaseApp.getContext()));
        couponPtrlv.setAdapter(couponListAdaper);
        couponPtrlv.setOnRefreshListener(this);
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
            
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

    }

    public void getData() {
        for (int i = 0; i < 10; i++) {
            couponDates.add(new ListMessage("sdf" + i, "sdfsdlfsdlf" + i, "20389" + i, null));
        }
    }
}
